﻿using System;
using System.ServiceProcess;
using System.Timers;
using QuickPrompt.BusinessService;
using QuickPromt.Service;
using Timer = System.Timers.Timer;

namespace QuickPrompt.WindowsService
{
    public partial class QuickPromptService : ServiceBase
    {
        private readonly IQuickNoteService _quickNoteService;
        private readonly Timer _timer = new Timer(TimeSpan.FromMinutes(5).Milliseconds);

        public QuickPromptService(QuickNoteService quickNoteService)
        {
            _quickNoteService = quickNoteService;
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            _timer.Elapsed += RunPrompts;
            _timer.Enabled = true;
        }

        private void RunPrompts(object sender, ElapsedEventArgs e)
        {
            _quickNoteService.QueuePrompts();
        }

        protected override void OnStop()
        {
            _timer.Enabled = false;
        }

    }
}
